<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // push的方法,向数组中添加一个或者多个元素,添加在末尾,返回的是数组的长度
    let  food = ['鸡蛋','啤酒','面包']
    let length = food.push('牛奶')
    console.log(length); // 4
    console.log(food); // ["鸡蛋", "啤酒", "面包", "牛奶"]
    food.push('西瓜', '南瓜', '北瓜', '冬瓜')
    console.log(food); // ["鸡蛋", "啤酒", "面包", "牛奶", "西瓜", "南瓜", "北瓜", "冬瓜"]

    // *************************************************************************************************
    // pop 尾部删除
    let food1 = food.pop()
    console.log(food1);  // 冬瓜
    console.log(food); //  ["鸡蛋", "啤酒", "面包", "牛奶", "西瓜", "南瓜", "北瓜"]


    // unshift 向数组的头部添加新的元素,参数为新添加的元素,返回新数组长度
    let good = ['面包','牛奶','西瓜']
    let long = good.unshift('豆腐')
    console.log(long) // 4
    console.log(good) // ["豆腐", "面包", "牛奶", "西瓜"]

    // shift 从数组中删除第一个元素,返回改元素,数组的长度会发生改变
    let goods = ["豆腐", "面包", "牛奶", "西瓜"]
    let good1 = goods.shift()
    console.log(good1); // 豆腐
    console.log(goods); // ["面包", "牛奶", "西瓜"]
  </script>
</body>
</html>